package com.srwl.mytx.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;

import com.srwl.mytx.R;
import com.srwl.mytx.domain.MyFile;
import com.srwl.mytx.widget.MyFileRepositoryDialog;

import java.util.ArrayList;
import java.util.List;

public class MyFileSelectActivity extends BaseActivity {

    public static void startActivity(Activity activity, int videoLimit, int pictureLimit, boolean isSelectOneType, ArrayList<MyFile> historySelectFile, int requestCode) {

        Intent intent = new Intent(activity, MyFileSelectActivity.class);
        intent.putExtra("videoLimit", videoLimit);
        intent.putExtra("pictureLimit", pictureLimit);
        intent.putExtra("isSelectOneType", isSelectOneType);
        intent.putExtra("historySelectFile", historySelectFile);
        activity.startActivityForResult(intent, requestCode);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_file_select);
        int videoLimit = getIntent().getIntExtra("videoLimit", 1);
        int pictureLimit = getIntent().getIntExtra("pictureLimit", 9);
        boolean isSelectOneType = getIntent().getBooleanExtra("isSelectOneType", false);
        ArrayList<MyFile> historySelectFile = getIntent().getParcelableArrayListExtra("historySelectFile");
        MyFileRepositoryDialog myFileRepositoryDialog = MyFileRepositoryDialog.newInstance(videoLimit, pictureLimit, isSelectOneType, historySelectFile);
        myFileRepositoryDialog.setListener(new MyFileRepositoryDialog.InteractionListener() {
            @Override
            public void onConfirm(ArrayList<MyFile> videoFiles, ArrayList<MyFile> pictureFiles) {

                Intent intent = new Intent();
                intent.putParcelableArrayListExtra("videoFiles",videoFiles);
                intent.putParcelableArrayListExtra("pictureFiles",pictureFiles);
                setResult(RESULT_OK,intent);
                finish();
            }
        });
        getSupportFragmentManager().beginTransaction().add(R.id.cl_container, myFileRepositoryDialog, "").commit();

    }
}
